package com.ym.b2b.user.dao.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Repository;

import com.ym.b2b.commons.dao.BaseDao;
import com.ym.b2b.user.dao.AgentUserDao;
import com.ym.b2b.user.sqlbean.AgentBuyer;
import com.ym.b2b.user.sqlbean.AgentProvider;
import com.zc.commons.base.Page;

/**
 * @ClassName: AgentBuyerDaoImpl
 * @Description: TODO
 * @Author tangxj
 * @Date 2015-3-24 上午11:19:55
 * @Modify
 * @CopyRight B2B小组
 */
@Repository
public class AgentUserDaoImpl<T> extends BaseDao<T> implements AgentUserDao {

    @Override
    public Page<AgentBuyer> searchPageAgentBuyer(AgentBuyer agentBuyer, Page<AgentBuyer> page)
                                                                                              throws DataAccessException {
        page.setTotalRow(searchAgentBuyerNum(agentBuyer));
        Map<String, Object> hmap = new HashMap<String, Object>();
        hmap.put("map", agentBuyer);
        hmap.put("startrow", page.getStartRow());
        hmap.put("pagesize", page.getPageSize());
        hmap.put("pageable", page.getPageable());
        page.setRows(list("AGENT_BUYER.searchPageAgentBuyer", hmap));
        return page;
    }

    @Override
    public Long searchAgentBuyerNum(AgentBuyer agentBuyer) throws DataAccessException {
        Map<String, Object> hmap = new HashMap<String, Object>();
        hmap.put("map", agentBuyer);
        return (Long) listNum("AGENT_BUYER.searchAgentBuyerNum", hmap);
    }

    @Override
    public Page<AgentProvider> searchPageAgentProvider(AgentProvider agentProvider, Page<AgentProvider> page)
                                                                                                             throws DataAccessException {
        page.setTotalRow(searchAgentProviderNum(agentProvider));
        Map<String, Object> hmap = new HashMap<String, Object>();
        hmap.put("map", agentProvider);
        hmap.put("startrow", page.getStartRow());
        hmap.put("pagesize", page.getPageSize());
        hmap.put("pageable", page.getPageable());
        page.setRows(list("AGENT_PROVIDER.searchPageAgentProvider", hmap));
        return page;
    }

    @Override
    public Long searchAgentProviderNum(AgentProvider agentProvider) throws DataAccessException {
        Map<String, Object> hmap = new HashMap<String, Object>();
        hmap.put("map", agentProvider);
        return (Long) listNum("AGENT_PROVIDER.searchAgentProviderNum", hmap);
    }

}
